/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.smart.hawk.view.impl;


import co.com.smart.hawk.controller.*;
import co.com.smart.hawk.controller.impl.HawkCiudadesCtrlImpl;
import co.com.smart.hawk.controller.impl.HawkDatosMaestrosCtrlImpl;
import co.com.smart.hawk.controller.impl.HawkDepartamentosCtrlImpl;
import co.com.smart.hawk.controller.impl.HawkTercerosCtrlImpl;
import co.com.smart.hawk.dto.*;
import co.com.smart.hawk.utilities.*;
import co.com.smart.hawk.view.HawkEmpresasView;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

/**
 *
 * @author Carlos Enaldo Ramos Hoyos
 */
public class HawkEmpresasViewImpl extends javax.swing.JInternalFrame implements HawkEmpresasView{

    ArrayList listDepartamentos, listCiudad, listRegimen, listTipoDocumento;
    private HawkEmpresasCtrl controller;
    private HawkDatosMaestrosCtrl controllerDatosMaestros;
    private HawkDepartamentosCtrl controllerDepartamentos;
    private HawkTercerosCtrl controllerTerceros;
    private HawkCiudadesCtrl controllerCiudades;
    private HawkComboBoxMgr<CiudadDTO> comboMgrCiudad;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrTipoEmpresa;
    private HawkComboBoxMgr<DepartamentoDTO> comboMgrDepartamento;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrTipoDocumento;
    private HawkTextFieldMgr textMgr;
    private HawkTableMgr<EmpresaDTO> tableMgrEmpresa;
    /**
     * Creates new form HawkEmpresasViewImpl
     */
    public HawkEmpresasViewImpl(JDesktopPane desktoppane, HawkEmpresasCtrl hawkEmpresasCtrl) {
        if (HawkViewMgr.getInstance().getObjectInstance(this.getClass()) == null) {
            try {
                this.controller = hawkEmpresasCtrl;
                textMgr = new HawkTextFieldMgr();
                initComponents();
                this.initEvent();
                this.initComponentsEmpresa();
                java.awt.Dimension dimension = desktoppane.size();
                java.awt.Dimension ventan = this.getSize();
                this.setLocation(new java.awt.Point((dimension.width - ventan.width) / 2, (dimension.height - ventan.height) / 2));
                HawkViewMgr.getInstance().setObjectInstance(this);
            } catch (Throwable ex) {
                ex.printStackTrace();
            }  
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        btnGrabar = new javax.swing.JButton();
        btnConsultar = new javax.swing.JButton();
        btnConsultar2 = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtCorepresentantelegal = new javax.swing.JTextField();
        txtDSrepresentantelegal = new javax.swing.JTextField();
        txtScrepresentantelegal = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        cbTipoDocumento = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        txtCoempresa = new javax.swing.JTextField();
        txtNmverificacion = new javax.swing.JTextField();
        txtDsempresa = new javax.swing.JTextField();
        txtDsnombrecorto = new javax.swing.JTextField();
        txtDsdireccion = new javax.swing.JTextField();
        txtDstelefono = new javax.swing.JTextField();
        cbCiudad = new javax.swing.JComboBox();
        txtDsemail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cbTipoEmpresa = new javax.swing.JComboBox();
        txtScempresa = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cbDepartamento = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbEmpresa = new javax.swing.JTable();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("SmartHawk - Empresas");

        jPanel1.setBackground(new java.awt.Color(153, 153, 153));

        jPanel2.setBackground(new java.awt.Color(51, 51, 51));

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Empresas");

        btnGrabar.setBackground(new java.awt.Color(255, 255, 255));
        btnGrabar.setForeground(new java.awt.Color(255, 255, 255));
        btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/guardar.png"))); // NOI18N
        btnGrabar.setBorderPainted(false);
        btnGrabar.setOpaque(false);
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        btnConsultar.setBackground(new java.awt.Color(255, 255, 255));
        btnConsultar.setForeground(new java.awt.Color(255, 255, 255));
        btnConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/consultar.png"))); // NOI18N
        btnConsultar.setBorderPainted(false);
        btnConsultar.setOpaque(false);
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        btnConsultar2.setBackground(new java.awt.Color(255, 255, 255));
        btnConsultar2.setForeground(new java.awt.Color(255, 255, 255));
        btnConsultar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/limpiar.png"))); // NOI18N
        btnConsultar2.setBorderPainted(false);
        btnConsultar2.setOpaque(false);
        btnConsultar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultar2ActionPerformed(evt);
            }
        });

        btnEliminar.setBackground(new java.awt.Color(255, 255, 255));
        btnEliminar.setForeground(new java.awt.Color(255, 255, 255));
        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/eliminar.png"))); // NOI18N
        btnEliminar.setBorderPainted(false);
        btnEliminar.setOpaque(false);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnGrabar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(btnConsultar2, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnGrabar))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(btnConsultar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnConsultar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnEliminar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(102, 255, 153));

        jPanel4.setBackground(new java.awt.Color(0, 204, 102));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel2.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel2.setText("Nit*");

        jLabel3.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel3.setText("Razón social*");

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel4.setText("Nombre corto*");

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel5.setText("Dirección*");

        jLabel6.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel6.setText("Teléfono*");

        jLabel7.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel7.setText("Ciudad*");

        jLabel8.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel8.setText("Número de verificación");

        jPanel5.setBackground(new java.awt.Color(0, 204, 102));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos representante legal", 0, 0, new java.awt.Font("Verdana", 1, 10))); // NOI18N

        jLabel9.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel9.setText("Identificación*");

        jLabel10.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel10.setText("Nombre*");

        txtCorepresentantelegal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCorepresentantelegalKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCorepresentantelegalKeyTyped(evt);
            }
        });

        txtDSrepresentantelegal.setEditable(false);

        jLabel14.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel14.setText("Tipo identificación*");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbTipoDocumento, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel9)
                .addGap(2, 2, 2)
                .addComponent(txtCorepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtDSrepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(txtScrepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(txtCorepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDSrepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtScrepresentantelegal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(cbTipoDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jLabel11.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel11.setText("Email");

        txtCoempresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCoempresaKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCoempresaKeyTyped(evt);
            }
        });

        txtNmverificacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNmverificacionKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNmverificacionKeyTyped(evt);
            }
        });

        txtDsempresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDsempresaKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDsempresaKeyTyped(evt);
            }
        });

        txtDsnombrecorto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDsnombrecortoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDsnombrecortoKeyTyped(evt);
            }
        });

        txtDsdireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDsdireccionKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDsdireccionKeyTyped(evt);
            }
        });

        txtDstelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDstelefonoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDstelefonoKeyTyped(evt);
            }
        });

        cbCiudad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCiudadActionPerformed(evt);
            }
        });

        txtDsemail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDsemailKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDsemailKeyTyped(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel12.setText("Régimen*");

        cbTipoEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTipoEmpresaActionPerformed(evt);
            }
        });

        txtScempresa.setAlignmentX(0.0F);
        txtScempresa.setAlignmentY(0.0F);

        jLabel13.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        jLabel13.setText("Departamento*");

        cbDepartamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDepartamentoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtScempresa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2))
                                .addGap(31, 31, 31)
                                .addComponent(txtCoempresa, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNmverificacion, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel13))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cbDepartamento, 0, 156, Short.MAX_VALUE)
                                    .addComponent(txtDsnombrecorto))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel5))))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addGap(39, 39, 39)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtDsempresa, javax.swing.GroupLayout.PREFERRED_SIZE, 423, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 83, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDsdireccion)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(cbCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel11)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtDsemail, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(17, 17, 17)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cbTipoEmpresa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txtDstelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)))))
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap(13, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(txtCoempresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(txtNmverificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDsempresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(txtDsnombrecorto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDsdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDstelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(cbCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(txtDsemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(cbTipoEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(cbDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(txtScempresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4))
        );

        jLabel12.getAccessibleContext().setAccessibleName("");
        jLabel12.getAccessibleContext().setAccessibleDescription("");

        jPanel6.setBackground(new java.awt.Color(0, 204, 102));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Listado de resoluciones", 0, 0, new java.awt.Font("Verdana", 1, 10))); // NOI18N

        tbEmpresa.setAutoCreateRowSorter(true);
        tbEmpresa.setBackground(new java.awt.Color(204, 204, 255));
        tbEmpresa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nit", "Empresa", "Dirección", "Representante legal", "Acción"
            }
        ));
        tbEmpresa.setSelectionForeground(new java.awt.Color(204, 204, 255));
        tbEmpresa.setShowHorizontalLines(false);
        jScrollPane1.setViewportView(tbEmpresa);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
        // TODO add your handling code here:
        grabarEmpresa();
    }//GEN-LAST:event_btnGrabarActionPerformed

    private void cbDepartamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDepartamentoActionPerformed
        // TODO add your handling code here:
        listarCiudades();
    }//GEN-LAST:event_cbDepartamentoActionPerformed

    private void txtNmverificacionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNmverificacionKeyTyped
        // TODO add your handling code here:
        textMgr.validarNumericos(evt, txtNmverificacion, 2);
    }//GEN-LAST:event_txtNmverificacionKeyTyped

    private void txtDsempresaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsempresaKeyTyped
        // TODO add your handling code here:
        textMgr.remplazarMayusculas(evt, txtDsempresa, 150);
    }//GEN-LAST:event_txtDsempresaKeyTyped

    private void txtDsnombrecortoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsnombrecortoKeyTyped
        // TODO add your handling code here:
        textMgr.remplazarMayusculas(evt, txtDsnombrecorto, 50);
    }//GEN-LAST:event_txtDsnombrecortoKeyTyped

    private void txtDsdireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsdireccionKeyTyped
        // TODO add your handling code here:
        textMgr.validarTamano(evt, txtDsdireccion, 250);
    }//GEN-LAST:event_txtDsdireccionKeyTyped

    private void txtDstelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDstelefonoKeyTyped
        // TODO add your handling code here:
        textMgr.validarNumericos(evt, txtDstelefono, 10);
    }//GEN-LAST:event_txtDstelefonoKeyTyped

    private void txtDsemailKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsemailKeyTyped
        // TODO add your handling code here:
        textMgr.validarTamano(evt, txtDsdireccion, 150);
    }//GEN-LAST:event_txtDsemailKeyTyped

    private void txtCorepresentantelegalKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCorepresentantelegalKeyTyped
        // TODO add your handling code here:
        textMgr.validarTamano(evt, txtCorepresentantelegal, 50);
    }//GEN-LAST:event_txtCorepresentantelegalKeyTyped

    private void txtCoempresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCoempresaKeyPressed
        // TODO add your handling code here:
       if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            txtNmverificacion.grabFocus();
        }
    }//GEN-LAST:event_txtCoempresaKeyPressed

    private void txtCorepresentantelegalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCorepresentantelegalKeyPressed
        // TODO add your handling code here:
         if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){ 
            consultarTerceros();
        }
    }//GEN-LAST:event_txtCorepresentantelegalKeyPressed

    private void txtNmverificacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNmverificacionKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            txtDsempresa.grabFocus();
            consultarEmpresas();
        }
    }//GEN-LAST:event_txtNmverificacionKeyPressed

    private void txtCoempresaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCoempresaKeyTyped
        // TODO add your handling code here:
        textMgr.validarNumericos(evt, txtCoempresa, 50);
    }//GEN-LAST:event_txtCoempresaKeyTyped

    private void txtDsempresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsempresaKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            txtDsnombrecorto.grabFocus();
        }        
    }//GEN-LAST:event_txtDsempresaKeyPressed

    private void txtDsnombrecortoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsnombrecortoKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            txtDsdireccion.grabFocus();
        }
    }//GEN-LAST:event_txtDsnombrecortoKeyPressed

    private void txtDsdireccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsdireccionKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            txtDstelefono.grabFocus();
        }
    }//GEN-LAST:event_txtDsdireccionKeyPressed

    private void txtDstelefonoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDstelefonoKeyPressed
        // TODO add your handling code here:
         if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            cbDepartamento.grabFocus();
        }
    }//GEN-LAST:event_txtDstelefonoKeyPressed

    private void cbCiudadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCiudadActionPerformed
        // TODO add your handling code here:
        txtDsemail.grabFocus();
    }//GEN-LAST:event_cbCiudadActionPerformed

    private void txtDsemailKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDsemailKeyPressed
        // TODO add your handling code here:
         if(evt.getKeyCode() == KeyEvent.VK_ENTER || evt.getKeyCode() == KeyEvent.VK_TAB){
            cbTipoEmpresa.grabFocus();
        }        
    }//GEN-LAST:event_txtDsemailKeyPressed

    private void cbTipoEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTipoEmpresaActionPerformed
        // TODO add your handling code here:
        txtCorepresentantelegal.grabFocus();
    }//GEN-LAST:event_cbTipoEmpresaActionPerformed

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        // TODO add your handling code here:
        listarEmpresas();
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void btnConsultar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultar2ActionPerformed
        // TODO add your handling code here:
        limpiarFormulario();
    }//GEN-LAST:event_btnConsultar2ActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnEliminarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnConsultar2;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGrabar;
    private javax.swing.JComboBox cbCiudad;
    private javax.swing.JComboBox cbDepartamento;
    private javax.swing.JComboBox cbTipoDocumento;
    private javax.swing.JComboBox cbTipoEmpresa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbEmpresa;
    private javax.swing.JTextField txtCoempresa;
    private javax.swing.JTextField txtCorepresentantelegal;
    private javax.swing.JTextField txtDSrepresentantelegal;
    private javax.swing.JTextField txtDsdireccion;
    private javax.swing.JTextField txtDsemail;
    private javax.swing.JTextField txtDsempresa;
    private javax.swing.JTextField txtDsnombrecorto;
    private javax.swing.JTextField txtDstelefono;
    private javax.swing.JTextField txtNmverificacion;
    private javax.swing.JTextField txtScempresa;
    private javax.swing.JTextField txtScrepresentantelegal;
    // End of variables declaration//GEN-END:variables

    @Override
    public void initEvent() {
        
            this.addInternalFrameListener(new InternalFrameAdapter() {

            @Override
            public void internalFrameClosing(InternalFrameEvent e) {
                SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        return null;
                    }

                    @Override
                    protected void done() {
                        cancelarProceso();
                    }
                };
                
                worker.execute();
            }
        });
    }

    @Override
    public void initComponentsEmpresa() {
        controllerDatosMaestros =  new HawkDatosMaestrosCtrlImpl();
        controllerDepartamentos = new HawkDepartamentosCtrlImpl();
        controllerTerceros = new HawkTercerosCtrlImpl();
        controllerCiudades = new HawkCiudadesCtrlImpl();
        txtScempresa.setVisible(false);
        txtScrepresentantelegal.setVisible(false);
        txtScempresa.setText("0");
        txtScrepresentantelegal.setText("0");
        cargarDatosMaestros();
        listarDepartamentos();
        listarEmpresas();
        txtCoempresa.grabFocus();
    }

    @Override
    public void cargarDatosMaestros() {
        MaestrosDTO tipoEmpresa = new MaestrosDTO();
        DatosMaestrosDTO filtroTipoEmpresa = new DatosMaestrosDTO();
        MaestrosDTO tipoDocumento = new MaestrosDTO();
        DatosMaestrosDTO filtroTipoDocumento = new DatosMaestrosDTO();        

        tipoEmpresa.setComaestro(HawkConstantes.Maestros.TIPO_EMPRESA.getCodigoMestro());
        filtroTipoEmpresa.setScmaestro(tipoEmpresa);
        tipoDocumento.setComaestro(HawkConstantes.Maestros.TIPO_DOCUMENTO.getCodigoMestro());
        filtroTipoDocumento.setScmaestro(tipoDocumento);       
        
        try {
            controllerDatosMaestros.cargarDatosMaestros(new Utility.CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    listRegimen = new ArrayList<>(object);
                    comboMgrTipoEmpresa = new HawkComboBoxMgr<>(cbTipoEmpresa);
                    comboMgrTipoEmpresa.setEmptyValue(null);
                    comboMgrTipoEmpresa.setData(object);
                }
            }, filtroTipoEmpresa);
            
           controllerDatosMaestros.cargarDatosMaestros(new Utility.CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    listTipoDocumento = new ArrayList<>(object);
                    comboMgrTipoDocumento = new HawkComboBoxMgr<>(cbTipoDocumento);
                    comboMgrTipoDocumento.setEmptyValue(null);
                    comboMgrTipoDocumento.setData(object);
                }
            }, filtroTipoDocumento);
        } catch (Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error cargando datos :\n" + thr.getMessage(), "Error carga inicial", JOptionPane.ERROR_MESSAGE);
        }
    }

    @Override
    public void cancelarProceso() {
        int message = JOptionPane.showConfirmDialog(this, "Está seguro que desea salir?", "Salir", JOptionPane.YES_NO_OPTION);
        if (message == JOptionPane.YES_OPTION) {
            HawkViewMgr.getInstance().removeObjectInstance(this.getClass());
            System.gc();
            this.dispose();
        }
    }

    @Override
    public void grabarEmpresa() {
        if (validarCampos()) {
          try {
              EmpresaDTO sendEmpresa = new EmpresaDTO();
              sendEmpresa = obtenerEmpresa();
              
              controller.grabarEmpresas(new Utility.CallBackSmartHawk<EmpresaDTO>(){
                    @Override
                    public void endProcess(EmpresaDTO object) {
                        JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this, object.getDsmensaje(), "Información", JOptionPane.INFORMATION_MESSAGE);
                        limpiarFormulario();
                    }
              },sendEmpresa);
                
          }catch(Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error almacenado la empresa: \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
            return;
          }
        }
    }

    private boolean validarCampos() {
        boolean flag = true;
        
        if (txtCoempresa == null || "".equals(txtCoempresa.getText())) {
            JOptionPane.showMessageDialog(this, "El NIT de la empresa es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
            txtCoempresa.grabFocus();
        }           
        
        if (txtDsempresa == null || "".equals(txtDsempresa.getText()) && flag) {
            JOptionPane.showMessageDialog(this, "La razón social de la empresa es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
            txtDsempresa.grabFocus();
        }

        if (txtDsnombrecorto == null || "".equals(txtDsnombrecorto.getText()) && flag) {
            JOptionPane.showMessageDialog(this, "El nombre corto de la empresa es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
            txtDsnombrecorto.grabFocus();
        }
        
        if (txtDsdireccion == null || "".equals(txtDsdireccion.getText()) && flag) {
            JOptionPane.showMessageDialog(this, "La dirección de la empresa es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
            txtDsdireccion.grabFocus();
        }       

        if (txtDstelefono == null || "".equals(txtDstelefono.getText()) && flag) {
            JOptionPane.showMessageDialog(this, "El teléfono de la empresa es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
            txtDstelefono.grabFocus();
        }
        
        if (this.comboMgrTipoEmpresa.getSelectedItem() == null && flag) {
            JOptionPane.showMessageDialog(this, "El tipo de empresa es obligatoria", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
        }

        if (this.comboMgrCiudad.getSelectedItem() == null && flag) {
            JOptionPane.showMessageDialog(this, "La ciudad es obligatoria", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
        }

        if (txtScrepresentantelegal == null && "".equals(txtScrepresentantelegal.getText()) && flag) {
            JOptionPane.showMessageDialog(this, "Debe seleccionar un representante legal dato obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
        }
          
        return flag;
    }

    @Override
    public void limpiarFormulario() {
            txtScempresa.setText("0");
            txtCoempresa.setText("");
            txtDsempresa.setText("");
            txtNmverificacion.setText("");
            txtDsnombrecorto.setText("");
            txtDsdireccion.setText("");
            txtDstelefono.setText("");
            comboMgrDepartamento.refresh();
            comboMgrCiudad = new HawkComboBoxMgr<>(cbCiudad);
            comboMgrCiudad.setData(null);
            comboMgrTipoDocumento.refresh();
            comboMgrTipoEmpresa.refresh();
            txtDsemail.setText("");
            txtScrepresentantelegal.setText("0");
            txtCorepresentantelegal.setText("");
            txtDSrepresentantelegal.setText("");
            txtCoempresa.grabFocus();
    }

    @Override
    public void listarDepartamentos() {
        PaisDTO paisDTO = new PaisDTO();
        DepartamentoDTO departamentoDTO = new DepartamentoDTO(); 
        
        paisDTO.setCopais(HawkConstantes.Maestros.PAIS_COL.getCodigoMestro());
        departamentoDTO.setPais(paisDTO);
        
        try{
            controllerDepartamentos.listarDepartamentos(new Utility.CallBackSmartHawk<List<DepartamentoDTO>>() {

                @Override
                public void endProcess(List<DepartamentoDTO> object) {
                    listDepartamentos = new ArrayList<>(object);
                    comboMgrDepartamento = new HawkComboBoxMgr<>(cbDepartamento);
                    comboMgrDepartamento.setEmptyValue(null);
                    comboMgrDepartamento.setData(object);
                }
            }, departamentoDTO);
        }catch(Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error cargando los departamentos :\n" + thr.getMessage(), "Error carga inicial", JOptionPane.ERROR_MESSAGE);
        }
    }

    @Override
    public void listarCiudades() {
        DepartamentoDTO departamentoDTO = new DepartamentoDTO(); 
        CiudadDTO ciudadDTO = new CiudadDTO();
        
        try{
            comboMgrCiudad = new HawkComboBoxMgr<>(cbCiudad);
            comboMgrCiudad.setEmptyValue(null);
            comboMgrCiudad.setData(null);
            if(this.comboMgrDepartamento.getSelectedItem() != null){   
                departamentoDTO = comboMgrDepartamento.getSelectedItem();
                ciudadDTO.setDepartamento(departamentoDTO);
                
                controllerCiudades.listarCiudades(new Utility.CallBackSmartHawk<List<CiudadDTO>>() {
                    @Override
                    public void endProcess(List<CiudadDTO> object) {
                        listCiudad = new ArrayList<>(object);
                        comboMgrCiudad = new HawkComboBoxMgr<>(cbCiudad);
                        comboMgrCiudad.setEmptyValue(null);
                        comboMgrCiudad.setData(object);
                        cbCiudad.grabFocus();
                    }
                }, ciudadDTO);
            }
        }catch(Throwable thr){
            JOptionPane.showMessageDialog(this, "Error cargando las ciudades :\n" + thr.getMessage(), "Error carga inicial", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    @Override
    public EmpresaDTO obtenerEmpresa(){
        EmpresaDTO empresaDTO = new EmpresaDTO();
        CiudadDTO ciudadDTO = new CiudadDTO();
        DatosMaestrosDTO tipoEmpresaDTO = new DatosMaestrosDTO();
        DatosMaestrosDTO tipoDocumentoDTO = new DatosMaestrosDTO();
        TerceroDTO representanteDTO = new TerceroDTO();
        
        empresaDTO.setScempresa(new BigDecimal(txtScempresa.getText()));
        empresaDTO.setCoempresa(txtCoempresa.getText());
        empresaDTO.setNmverificacion(Integer.parseInt(txtNmverificacion.getText()));
        empresaDTO.setDsempresa(txtDsempresa.getText());
        empresaDTO.setDsnombrecorto(txtDsnombrecorto.getText());
        empresaDTO.setDsdireccion(txtDsdireccion.getText());
        empresaDTO.setDstelefono(txtDstelefono.getText());
        ciudadDTO = comboMgrCiudad.getSelectedItem();
        empresaDTO.setCiudad(ciudadDTO);
        empresaDTO.setDsemail(txtDsemail.getText());
        tipoEmpresaDTO = comboMgrTipoEmpresa.getSelectedItem();
        empresaDTO.setTipoempresa(tipoEmpresaDTO);
        representanteDTO.setSctercero(new BigDecimal(txtScrepresentantelegal.getText()));
        empresaDTO.setRepresentante(representanteDTO);
        tipoDocumentoDTO = comboMgrTipoDocumento.getSelectedItem();
        empresaDTO.setTipodocumento(tipoDocumentoDTO);
        
        return empresaDTO;
    }

    @Override
    public void listarEmpresas(){
        try {
            EmpresaDTO empresa = new EmpresaDTO();
            tableMgrEmpresa = new HawkTableMgr<>(tbEmpresa);
            tableMgrEmpresa.setPosition(HawkTableMgr.PositionObject.LAST);
            JLabel buscar = new JLabel(new ImageIcon(getClass().getResource("/img/search_grid.png")));
            buscar.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    try {
                        //ejecuta evento al dar clic en el boton de la tabla
                    } catch (Throwable ex) {
                        ex.printStackTrace(System.err);
                    }
                }


            });
            tableMgrEmpresa.addNewValueColumn(buscar);
            controller.listarEmpresas(new Utility.CallBackSmartHawk<List<EmpresaDTO>>() {
                @Override
                public void endProcess(List<EmpresaDTO> object) {
                    try{
                        tableMgrEmpresa.clearAll();
                        tableMgrEmpresa.setData(object);
                    }catch(Throwable ex) {
                        ex.printStackTrace(System.err);
                        JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    }               
                }
            }, empresa);
        
        } catch (Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error al listar empresas: \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    @Override
    public void consultarTerceros() {
        TerceroDTO tercero = new TerceroDTO();
        try{
            DatosMaestrosDTO tipoDocumentoDTO = new DatosMaestrosDTO();
            tipoDocumentoDTO = comboMgrTipoDocumento.getSelectedItem();
            tercero.setTipodocumento(tipoDocumentoDTO);
            tercero.setCoidentificacion(txtCorepresentantelegal.getText());
            controllerTerceros.consultarTerceros(new Utility.CallBackSmartHawk<TerceroDTO>() {
                @Override
                public void endProcess(TerceroDTO object) { 
                    try{
                        if (object.getSctercero()!= null){
                            txtScrepresentantelegal.setText((object.getSctercero()).toString());
                            txtDSrepresentantelegal.setText(object.getNombrecontatenado());
                            txtCoempresa.grabFocus();  
                        }else{
                             JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this,  "El tercero no se encuentra \n", "Información", JOptionPane.INFORMATION_MESSAGE);
                        }
                    }catch(Throwable ex) {
                        ex.printStackTrace(System.err);
                        JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this,  "Error al consultar el tercero \n" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    }
                }               
            },tercero);
        }catch(Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error al consultar el tercero \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    @Override
    public void consultarEmpresas() {
        EmpresaDTO empresa = new EmpresaDTO();
        try{
            empresa.setCoempresa(txtCoempresa.getText());
            empresa.setNmverificacion(Integer.parseInt(txtNmverificacion.getText()));
            controller.consultarEmpresas(new Utility.CallBackSmartHawk<EmpresaDTO>(){

                @Override
                public void endProcess(EmpresaDTO object) {
                    try{
                       if(object!=null){
                            cargarComponentes(object);
                       }else{
                            JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this, "No se encuentran con el NIT y Número de verificación ingresado", "Error procesando", JOptionPane.ERROR_MESSAGE);
                       }
                    }catch(Throwable ex) {
                        ex.printStackTrace(System.err);
                        JOptionPane.showMessageDialog(HawkEmpresasViewImpl.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    } 
                }
            }, empresa);
            
        }catch(Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error al consultar el tercero \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    @Override
    public void cargarComponentes(EmpresaDTO object) {
        try{
            txtScempresa.setText(object.getScempresa().toString());
            txtScrepresentantelegal.setText(object.getRepresentante().getSctercero().toString());
            txtDsempresa.setText(object.getDsempresa());
            txtDsnombrecorto.setText(object.getDsnombrecorto()); 
            txtDsdireccion.setText(object.getDsdireccion());
            txtDstelefono.setText(object.getDstelefono());
            txtDsemail.setText(object.getDsemail());
            txtCorepresentantelegal.setText(object.getRepresentante().getCoidentificacion());
            txtDSrepresentantelegal.setText(object.getRepresentante().getNombrecontatenado());
            cbDepartamento.setSelectedIndex(obtenerPosicionDepartamento(object.getCiudad().getDepartamento()));
            cbCiudad.setSelectedIndex(obtenerPosicionCiudad(object.getCiudad()));
            cbTipoEmpresa.setSelectedIndex(obtenerPosicionRegimen(object.getTipoempresa()));
            cbTipoDocumento.setSelectedIndex(obtenerPosicionTipoDocumento(object.getRepresentante().getTipodocumento()));
            txtCoempresa.grabFocus();
        }catch(Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error al mostrar datos \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    public int obtenerPosicionDepartamento(DepartamentoDTO object){
        for(int i=0;i<=listDepartamentos.size();i++){
            DepartamentoDTO departamento = new DepartamentoDTO();
            departamento = (DepartamentoDTO)listDepartamentos.get(i);
            if(departamento.getScdepartamento().equals(object.getScdepartamento())){
                return i+1;
            }
        }  
        return 0;
    }
    
    public int obtenerPosicionCiudad(CiudadDTO object){
        for(int i=0;i<=listCiudad.size();i++){
            CiudadDTO ciudad = new CiudadDTO();
            ciudad = (CiudadDTO)listCiudad.get(i);
            if(ciudad.getScciudad().equals(object.getScciudad())){
                return i+1;
            }
        }  
        return 0;
    }
    
    public int obtenerPosicionRegimen(DatosMaestrosDTO object){
        for(int i=0;i<=listRegimen.size();i++){
            DatosMaestrosDTO datosMaestros = new DatosMaestrosDTO();
            datosMaestros = (DatosMaestrosDTO)listRegimen.get(i);
            if(datosMaestros.getScdatmaestro().equals(object.getScdatmaestro())){
                return i+1;
            }
        }  
        return 0;
    }
    
   public int obtenerPosicionTipoDocumento(DatosMaestrosDTO object){
        for(int i=0;i<=listTipoDocumento.size();i++){
            DatosMaestrosDTO datosMaestros = new DatosMaestrosDTO();
            datosMaestros = (DatosMaestrosDTO)listTipoDocumento.get(i);
            if(datosMaestros.getScdatmaestro().equals(object.getScdatmaestro())){
                return i+1;
            }
        }  
        return 0;
    }
}